package com.xiayuanxing.arithmetic.DataStructures.Recursion;

/**
 * @program: arithmetic
 * @description: 递归测试类
 * @author: xia yuan xing
 * @create: 2021-09-14 17:02
 */
public class RecurSionTest {

    public static void main(String[] args) {
        System.out.println("打印问题：=========================");
        test(10);
        System.out.println("阶乘问题：=========================");
        int factorial = factorial(4);
        System.out.println("返回结果："+factorial);
    }

    /**
     * 打印问题
     * @param n
     */
    public static void test(int n){
        if (n > 2){
            test(n - 1);
        }
        System.out.println("n=:"+n);
    }


    /**
     * 阶乘问题
     * @param n
     * @return
     */
    public static int factorial(int n){
        if (n == 1){
            return 1;
        }else {
            return factorial(n - 1)* n;
        }
    }
}